package com.udata.client.activity;

import com.google.gwt.activity.shared.AbstractActivity;
import com.google.gwt.event.shared.EventBus;
import com.google.gwt.place.shared.Place;
import com.google.gwt.user.client.ui.AcceptsOneWidget;
import com.udata.client.ClientFactory;
import com.udata.client.place.TiebaExpPlace;
import com.udata.client.view.TiebaExpView;

public class TiebaExpActivity extends AbstractActivity implements TiebaExpView.Presenter {
  // Used to obtain views, eventBus, placeController
  // Alternatively, could be injected via GIN
  private ClientFactory clientFactory;
  // Name that will be appended to "Hello,"
  private String        name;

  public TiebaExpActivity(TiebaExpPlace place, ClientFactory clientFactory) {
    this.name = place.getTokenName();
    this.clientFactory = clientFactory;
  }

  /**
   * Ask user before stopping this activity
   */
  @Override
  public String mayStop() {
    return "Please hold on. This activity is stopping.";
  }

  /**
   * Navigate to a new Place in the browser
   */
  public void goTo(Place place) {
    clientFactory.getPlaceController().goTo(place);
  }

  @Override
  public void start(AcceptsOneWidget containerWidget, EventBus eventBus) {
    TiebaExpView tiebaExpView = clientFactory.getTiebaExpView();
    tiebaExpView.setName(name);
    tiebaExpView.setPresenter(this);
    containerWidget.setWidget(tiebaExpView.asWidget());

  }
}